# coding: utf-8

import datetime

import operator
from enum import unique

# 将条件与具体的函数关联起来
from common.constant import StatusEnum

expression_dict = {
    '<': operator.lt,
    '<=': operator.le,
    '>': operator.gt,
    '>=': operator.ge,
    '=': operator.eq,
    '!=': operator.ne,
    '<>': operator.ne,
}


@unique
class Choice(StatusEnum):
    """
    用于选择是/否的通用常量
    """
    NO = (0, '否')
    YES = (1, '是')


@unique
class Gender(StatusEnum):
    """
    性别
    """
    FEMALE = (0, '女')
    MALE = (1, '男')


APP_CURRENT_TOKEN_KEY = '{user_id}_current_app_token'


class HttpCode(object):
    """
    存储http_code
    """
    SUCCESS = 200
    # 参数校验不通过时返回BAD_REQUEST
    BAD_REQUEST = 400
    UNAUTHORIZED = 401
    FORBIDDEN = 403
    NOT_FOUND = 404
    METHOD_NOT_ALLOWED = 405


def get_tomorrow_ten_oclock():
    today = datetime.date.today()
    tomorrow = today + datetime.timedelta(days=1)
    result = datetime.datetime(tomorrow.year, tomorrow.month, tomorrow.day, 10)
    return result


def get_tomorrow_fifteen_oclock():
    today = datetime.date.today()
    tomorrow = today + datetime.timedelta(days=1)
    result = datetime.datetime(tomorrow.year, tomorrow.month, tomorrow.day, 15)
    return result


def get_one_day_ago():
    today = datetime.date.today()
    tmp_result = today - datetime.timedelta(days=1)
    result = datetime.datetime(
        tmp_result.year, tmp_result.month, tmp_result.day)
    return result


def get_fifteen_day_ago():
    today = datetime.date.today()
    tmp_result = today - datetime.timedelta(days=15)
    result = datetime.datetime(
        tmp_result.year, tmp_result.month, tmp_result.day)
    return result


def get_thirty_day_ago():
    today = datetime.date.today()
    tmp_result = today - datetime.timedelta(days=30)
    result = datetime.datetime(
        tmp_result.year, tmp_result.month, tmp_result.day)
    return result
